package com.molyfun.parents.activity.common.listactivity.factory;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.molyfun.parents.MFPApplication;
import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.listactivity.AbstractListFactory;
import com.molyfun.parents.activity.common.listactivity.IResponse;
import com.molyfun.parents.activity.common.listactivity.viewholder.MsgViewHolder;
import com.molyfun.parents.rest.RestClient;
import com.molyfun.parents.rest.bean.MsgListResponse;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/31/16.
 *
 * 我的消息列表
 */
public class MsgFactory extends AbstractListFactory<MsgListResponse.MsgBean> {

    @Override
    public int getTitle() {
        return R.string.activity_title_mine_msg;
    }

    @Override
    public void getDataList(int pageNum,final IResponse responseCallback) {

        Call<MsgListResponse> call = MFPApplication.getInstance().getRestClient().getMsgList(pageNum, RestClient.DEFAULT_PAGE_SIZE);
        call.enqueue(new Callback<MsgListResponse>() {
            @Override
            public void onResponse(Call<MsgListResponse> call, Response<MsgListResponse> response) {
                if (response.body() != null && response.body().getData() != null && response.body().getData().getRecords() != null) {
                    responseCallback.onResponse(response.body().getData().getRecords());
                }
            }

            @Override
            public void onFailure(Call<MsgListResponse> call, Throwable t) {
            }
        });

    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(ViewGroup parent, int viewType) {
        return new MsgViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_msg_cell, parent, false));
    }

    @Override
    public void bindViewHolder(final Context context, final MsgListResponse.MsgBean msgBean, RecyclerView.ViewHolder holder, final int position, FragmentManager fragmentManager, int totalSize) {
        MsgViewHolder msgViewHolder = (MsgViewHolder)holder;
        msgViewHolder.mMsgItemView.initData(msgBean);
//        msgViewHolder.mMsgItemView.setOnLongClickListener(new View.OnLongClickListener() {
//            @Override
//            public boolean onLongClick(View v) {
//                if (mOnListOperationCallback != null) {
//                    mOnListOperationCallback.onLongClick(msgBean.getId());
//                }
//                return false;
//            }
//        });
    }

    @Override
    public void deleteData(String id, int position) {

    }

}
